<template>
  <div id="dd">
    <div
      id="myChart1"
      :style="{ width: '700px', height: '500px', background: '#ffffff' }"
    ></div>
  
  </div>
</template>
 
<script>
import * as echarts from "echarts/core";
import {
  getNews,
  getAdminSer,
  getCommentSer,
  getProduce,
  getUserSer,
} from "@/api/table";
export default {
  data() {
    return {
      // 定义图表，各种参数
      msg: "扇形图",
      count:'',
      count1:'',
      count2:'',
      count3:'',
      count4:'',
      datas: [
        { value: 6, name: "管理员数" },
        { value: 2, name: "用户人数" },
        { value: 5, name: "手机新闻" },
        { value: 14, name: "用户评论数" },
        { value: 45, name: "手机产品数" },
        { value: 5, name: "分类" },

      ],
    };
  },
  mounted() {
    this.drawLine(); //按照默认值绘制图表
  

  },
  created() {
    this.getDate()
    // console.log(this.count);
    // console.log(this.count1);
    // console.log(this.count2);
    // console.log(this.count3);
    // console.log(this.count4);

  },
  watch: {
    datas: {
      handler: function () {
        this.drawLine();
      
      },
      deep: true,
    },
  },
  methods: {
    drawLine() {
      // 1、基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById("myChart1"));
      //2、构造图表数据
      let options = {
        title: {
          text: "数据一览表",
          left: "center",
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          data: ["管理员数", "用户人数", "手机新闻", "用户评论数","手机产品数","手机分类"],
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "55%",
            center: ["50%", "60%"],
            data: this.datas,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      // 3、绘制图表
      myChart.setOption(options);
    },
     getDate() {
      let params={}
      getNews(params).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          this.count = res.count;
          // console.log(this.count);
        }
      });
       getAdminSer(params).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          this.count1 = res.count;
          // console.log(this.count1);
        }
      });
        getUserSer(params).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          this.count2 = res.count;
          // console.log(this.count2);
        }
      });
        getProduce(params).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          this.count3 = res.count;
          // console.log(this.count3);
        }
      });
        getCommentSer(params).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          this.count4 = res.count;
          // console.log(this.count4);
        }
      });
    },
  },
};
</script>


<style lang="scss" scoped>
#dd{
  margin: 50px 100px;
}
</style> 